﻿using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using Ue.Eagle.Runtime.Models;
using Ue.Eagle.Runtime.Loaders;
using Ue.Eagle.Runtime.FileSystems.Dependencies;

namespace Ue.Eagle.Runtime
{
    public class PluginLoadingContext
    {
        public PluginLoadingContext()
        {
            ProcessedPlugins = new Dictionary<string, PluginProbeEntry>(StringComparer.OrdinalIgnoreCase);
            ProcessedReferences = new Dictionary<string, PluginReferenceProbeEntry>(StringComparer.OrdinalIgnoreCase);
            DeleteActions = new List<Action>();
            CopyActions = new List<Action>();
            NewDependencies = new List<DependencyDescriptor>();
        }

        /// <summary>
        /// 处理过的插件
        /// </summary>
        public IDictionary<string, PluginProbeEntry> ProcessedPlugins { get; private set; }
        /// <summary>
        /// 处理过的插件依赖
        /// </summary>
        public IDictionary<string, PluginReferenceProbeEntry> ProcessedReferences { get; private set; }

        /// <summary>
        /// 新插件描述列表
        /// </summary>
        public IList<DependencyDescriptor> NewDependencies { get; private set; }

        /// <summary>
        /// 删除动作
        /// </summary>
        public IList<Action> DeleteActions { get; private set; }
        /// <summary>
        /// 复制动作
        /// </summary>
        public IList<Action> CopyActions { get; private set; }

        /// <summary>
        /// 是否重启应用程序
        /// </summary>
        public bool RestartAppDomain { get; set; }

        /// <summary>
        /// 所有插件的VirtualPathDependencies文件的最后修改时间
        /// Key：VirtualPath
        /// Value:DateTime
        /// </summary>
        public ConcurrentDictionary<string, DateTime> VirtualPathModficationDates { get; set; }

        /// <summary>
        /// 系统中的插件列表
        /// </summary>
        public List<PluginDescriptor> AvailablePlugins { get; set; }

        /// <summary>
        /// 前一次系统成功动行时的插件描述列表
        /// </summary>
        public List<DependencyDescriptor> PreviousDependencies { get; set; }

        /// <summary>
        /// 与前一次系统运行对比，不在本次环境运行的插件描述列表
        /// </summary>
        public List<DependencyDescriptor> DeletedDependencies { get; set; }

        /// <summary>
        /// Key：插件名 
        /// Value：插件加载器列表
        /// 根据加载器优先级进行排序
        /// </summary>
        public IDictionary<string, IEnumerable<PluginProbeEntry>> AvailablePluginsProbes { get; set; }

        /// <summary>
        /// 插件依赖信息，根据插件名称进行分类
        /// Key：插件名称
        /// Value：插件所依赖的对象集合
        /// </summary>
        public IDictionary<string, IEnumerable<PluginReferenceProbeEntry>> ReferencesByModule { get; set; }

        /// <summary>
        /// 插件依赖信息，根据依赖对象名称进行分类
        /// Key：依赖对象名称
        /// Value：所有依赖当前对象的插件依赖信息
        /// </summary>
        public IDictionary<string, IEnumerable<PluginReferenceProbeEntry>> ReferencesByName { get; set; }
    }
}
